package com.nft.collection.service;

import com.nft.collection.repo.AirDropTaskRepo;
import com.nft.collection.repo.BankCardManagementRepp;
import com.nft.member.domain.BankCardManagement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Validated
@Service
public class BankCardManagementService {
    @Autowired
    private BankCardManagementRepp bankCardManagementRepp;
    public void addBankManage(BankCardManagement bankCardManagement) {
        bankCardManagementRepp.save(bankCardManagement);
    }

    public List<BankCardManagement> queryBackInfo() {
        List<BankCardManagement> all = bankCardManagementRepp.findByStatus("0");
        if(all.isEmpty()){
            return new ArrayList<>();
        }
        return all;
    }

    public void updateBackInfo(BankCardManagement bankCardManagement) {
        addBankManage(bankCardManagement);
    }

    public void deleteBackInfo(String id) {
        Optional<BankCardManagement> byId = bankCardManagementRepp.findById(id);
        BankCardManagement bankCardManagement = byId.get();
        bankCardManagement.setStatus("1");
        bankCardManagementRepp.save(bankCardManagement);
    }

    public BankCardManagement queryBackInfoById( String id) {
        return bankCardManagementRepp.findById(id).get();
    }
}
